<div class="layui-fluid">

    <div class="layui-row layui-col-space5">
        <script template type="text/html">
            {{#  layui.each(layui.admin.getPageAreas(),function(idx,item){ }}
            <div class="layui-col-md{{item.AreaCols}}">
                <div class="layui-card">
                    <div class="layui-card-header">{{item['PageName'+layui.admin.lang]}}</div>
                    {{# if(item.AreaType==='list'){ }}
                    <div class="layui-card-body">
                        <table id="{{item.Sign}}-table" lay-filter="{{item.Sign}}-table"></table>
                    </div>
                    {{# layui.data.doneList(item.Sign)} }}
                </div>
            </div>
            {{#  }) }}
        </script>
    </div>
</div>

<script>
    layui.data.doneList = function (sign) {
        layui.admin.req({
            type: 'post'
            , url: '/Tool/getTableConfig'
            , data: { TableNo: sign }
            , done(res) {
                if (res.data.tempTable) {
                    var tableId = sign
                        , searchFormNo = sign + '-search-form'
                        , subFormNo = sign + '-form';

                    var options = layui.admin.parse(res.data.tempTable);

                    if (options.options)
                        delete options.options;

                    options.buildType = 1;
                    options.tableId = tableId;

                    if (options.tableOptions) {
                        if (options.tableOptions.options)
                            delete options.tableOptions.options;

                        if (options.tableOptions.where) {
                            options.tableOptions.where = layui.admin.funObj(options.tableOptions.where);
                            if (options.tableOptions.where.SearchWhere)
                                options.tableOptions.where.SearchWhere = JSON.stringify(options.tableOptions.where.SearchWhere);
                        }

                        if (options.tableOptions.initSort)
                            options.tableOptions.initSort = layui.admin.funObj(options.tableOptions.initSort);
                    }

                    if (options.formOptions) {
                        if (options.formOptions.options)
                            delete options.formOptions.options;

                        if (options.formOptions && !options.formOptions.url && !options.formOptions.formLay && res.data.subForm) {
                            var subFormItemsData = layui.admin.parse(res.data.subForm);
                            var html = '<form class="layui-form " lay-filter="' + subFormNo + '" id="' + subFormNo + '">'
                                + layui.admin.getFormHtml(subFormItemsData)
                                + layui.admin.getFormBtn(sign)
                                + '</form>';
                            options.formOptions.formLay = subFormNo;
                            options.formOptions.formHtml = html;
                            options.formOptions.FormItemsData = subFormItemsData;
                        }
                    }

                    var searchFormItemsData, html = '';
                    if (res.data.searchForm) {
                       searchFormItemsData = layui.admin.parse(res.data.searchForm);
                         html = '<form class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="' + searchFormNo + '" id="' + searchFormNo + '">'
                            + layui.admin.getFormHtml(searchFormItemsData)
                            + '</form>';
                        layui.$('#' + tableId + '-table').parent().before(html);
                    }

                    if (options.tableType === 'table') {
                        layui.use('reTable', function () {
                            var $ = layui.$
                                , reTable = layui.reTable
                                , reForm = layui.reForm
                                , form = layui.form;

                            if (res.data.searchForm) {

                                $.each(searchFormItemsData, function (idx, json) {
                                    reForm.bindFormHtml(json, null, searchFormNo);
                                });

                                form.render(null, searchFormNo);
                            }

                            reTable.initTable(options);
                        })
                    } else {
                        layui.use('reTreeGrid', function () {
                            var $ = layui.$
                                , reTreeGrid = layui.reTreeGrid
                                , reForm = layui.reForm
                                , form = layui.form;

                            if (res.data.searchForm) {
                                
                                $.each(searchFormItemsData, function (idx, json) {
                                    reForm.bindFormHtml(json, null, searchFormNo);
                                });

                                form.render(null, searchFormNo);
                            }

                            reTreeGrid.initTreeGrid(options);
                        })
                    }
                }
            }
        })
    }
</script>